﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UrlEncoder.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// <summary>
//    Encodes url properties
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WP7Contrib.Communications
{
    using System.Net;

    /// <summary>
    /// Encodes url properties - use this encode parameters used in a query string
    /// </summary>
    public sealed class UrlEncoder : IEncodeProperties
    {
        /// <summary>
        /// Url Encodes a parameter
        /// </summary>
        /// <param name="param">
        /// The param to be encoded.
        /// </param>
        /// <returns>
        /// Returns the encoded param.
        /// </returns>
        public string Encode(object param)
        {
            var encoded = @param == null ? null : HttpUtility.UrlEncode(@param.ToString());
            if (encoded != null)
                encoded = encoded.Replace("+", "%20");

            return encoded;
        }
    }
}
